package core.jvm;

import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;

public class JvmAppClassLoaderAddUrl {

    public static void main(String[] args) {
        String appPath = "/Users/linglingdai/workspace/demo/code_algorithm/out/production/code_algorithm";
        URLClassLoader urlClassLoader = (URLClassLoader) JvmAppClassLoaderAddUrl.class.getClassLoader();

        Method addURL = null;
        try {
            addURL = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
            addURL.setAccessible(true);
            URL url = new URL(appPath);
            addURL.invoke(urlClassLoader, url);
            Class.forName("core.jvm.Hello").newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
